package cn.itsource.config;


import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.mapper.ISqlInjector;
import com.baomidou.mybatisplus.mapper.LogicSqlInjector;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Component
@Configuration
@MapperScan("cn.itsource.**.mapper") //mapper接口扫描
@EnableTransactionManagement  //事务管理
public class MybatisPlusConfig {
    // 逻辑删除组件！
    @Bean
    public ISqlInjector sqlInjector() {
        return new LogicSqlInjector();
    }

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
    /**
     * 分页插件
     */
//    @Bean
//    public PaginationInterceptor paginationInterceptors() {
//        PaginationInterceptor page = new PaginationInterceptor();
//        page.setDialectType("mysql");
//        return page;
//    }

    /**
     * 插件注册
     *
     * @param paginationInnerInterceptor 分页插件
     * @return MybatisPlus拦截器
     */
//    @Bean
//    public MybatisPlusInterceptor mybatisPlusInterceptor(PaginationInnerInterceptor paginationInnerInterceptor) {
//        MybatisPlusInterceptor mp = new MybatisPlusInterceptor();
//        mp.addInnerInterceptor(paginationInnerInterceptor);
//        return mp;
//    }
//
//    //分页插件
//    @Bean
//    public PaginationInnerInterceptor paginationInnerInterceptor() {
//        PaginationInnerInterceptor pii = new PaginationInnerInterceptor();
//        pii.setMaxLimit(20L);
//        pii.setDbType(DbType.MYSQL);
//        //当超过最大页数时不会报错
//        pii.setOverflow(true);
//        return pii;
//    }



}